/**
 * @class   wosh::network::libsockets::ServerTcpLS
 * @brief   The class provides a TCP socket.
 *
 * @todo    Add http://doc.trolltech.com/qq/qq17-ratecontrol.html
 ****************************************************************************
 * @version $Id: SocketTcpLS.h 2850 2010-08-06 18:49:18Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Network_libsockets_SocketTcpLS_H__
 #define __WOSH_Network_libsockets_SocketTcpLS_H__

#define _SocketTcp_DEBUG_ENABLED

 #include <core/Thread.h>
 #include <framework/network/SocketTcp.h>


class SocketTcpWrapper;
namespace Sockets {
	class SocketHandler;
};
//struct sockaddr;


namespace wosh {
 namespace network {
  namespace libsockets {


class ServerTcpLS;

class SocketTcpLS :		private ThreadImpl,
						public wosh::network::SocketTcp
 {
	WOSH_CLASSNAME(wosh::network::libsockets::SocketTcpLS)
	WOSH_CLASS_ABSTRACT(false)


	public:

		SocketTcpLS();

		virtual ~SocketTcpLS();

	public:

	//	using QTcpSocket::read;
	//	using QTcpSocket::readAll;

	public:

		virtual WRESULT connect( unsigned long timeout = LIMIT_ULONG_MAX );

		virtual WRESULT disconnect( unsigned long timeout = LIMIT_ULONG_MAX );

		virtual int64 read( char* output, int64 data_len );

		virtual int sendDatagram( const char* data, int size = 0 );

	//	virtual bool waitWritten( long timeout = 30000 );

	//	virtual bool waitResponse( char* data, int max_size, long& size, long timeout = 30000 );

		virtual WRESULT setSocket( int socket_descriptor );

		virtual inline bool isConnected() const;

/** @name Getters
 * @{
 ******************************************************************************/
	public:
		std::string getPeerAddressPort() const;

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:

//@}
/** @name Internal vars and methods
 * @{
 ******************************************************************************/
	protected:

		bool initializingThread();
		void runThread();
		void exitingThread();

		Sockets::SocketHandler* sHandler;
		SocketTcpWrapper* socketWapper;

		friend class SocketTcpWrapper;
		friend class wosh::network::ServerTcp;
		friend class wosh::network::libsockets::ServerTcpLS;

//@}


}; // class def

  }; // namespace libsockets
 }; // namespace network
}; // namespace wosh

#endif //__WOSH_Network_libsockets_SocketTcpLS_H__
